package com.rt.tmpt.dto;

import com.alibaba.fastjson.JSONObject;
import com.inspiresoftware.lib.dto.geda.annotations.Dto;
import com.inspiresoftware.lib.dto.geda.annotations.DtoCollection;
import com.inspiresoftware.lib.dto.geda.annotations.DtoField;
import com.rt.easyjava.common.utils.others.InvokeMethodUtils;
import com.rt.easyjava.common.utils.others.StringUtils;
import com.rt.tmpt.bean.*;
import lombok.Data;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

@Data
@Dto("com.rt.tmpt.bean.A1TemplateTable")
public class A1TemplateTableDto  implements Serializable{
	private static final long serialVersionUID = 1L;

	@DtoField
	private Long id;
	@DtoField
	private String keyRandom;
	@DtoField
	private String idType;
	@DtoField
	private String btnMulti;
	@DtoField
	private String tableName;
	@DtoField
	private String tableNameShow;
	@DtoField
	private String comment;
	@DtoField
	private String one2many;
	@DtoField
	private String primaryKey;
	@DtoField
	private String foreignKey;
	@DtoField
	private Integer mode;
	@DtoField
	private String tableAliasName;

	@DtoField
	private Integer hasAddBtn;
	@DtoField
	private Integer hasDownloadReportBtn;
	@DtoField
	private Integer hasEditBtn;
	@DtoField
	private Integer hasHistoryBtn;

	@DtoField
	private String beanObject;
	@DtoField
	private String beanMethod;
	@DtoField
	private String beanHistoryMethod;

	//拦截器对象和方法，添加、修改时，先执行这个
	@DtoField
	private String interceptObject;
	@DtoField
	private String interceptAddMethod;
	@DtoField
	private String interceptEditMethod;


	@DtoField
	private String tableNameSql;
	@DtoField
	private String tableNameHistorySql;

	@DtoField
	private String sqlPage;
	@DtoField
	private String sqlCount;
	@DtoField
	private String sqlSum;
	@DtoField
	private String sqlReport;
	@DtoField
	private String sqlPageHistory;
	@DtoField
	private String sqlCountHistory;

	@DtoField
	private Integer width4AddDialog ;
	@DtoField
	private Integer height4AddDialog ;
	@DtoField
	private String style4AddDialog ;
	@DtoField
	private Integer isdialog4AddDialog ;

	@DtoField
	private Integer hasCheckbox ;

	@DtoField
	private Integer deleteFlag ;//default0,1已删除
	@DtoField
	private Timestamp createDate ;
	@DtoField
	private Timestamp modifyDate ;
	@DtoField
	private String createMan ;
	@DtoField
	private String modifyMan ;

	//{"caption": "Website Visitors","subCaption": "Last week Vs This week", "xAxisName": "Day",
    //"yAxisName": "No. of Visitors","theme": "fint","showValues": "0","adjustDiv": "0","yAxisMaxvalue": "35000",
    //"yAxisMinValue": "5000","numDivLines": "9"}
	@DtoField
	private String chartJson;
	@DtoField
	private Integer chartWidth;
	@DtoField
	private Integer chartHeight;
	@DtoField
	private String dataSource;
	@DtoField
	private String treeJson;
	@DtoField
	private String version;

	@DtoCollection(
			value="a1TemplateColumnList",
			dtoToEntityMatcher= A1TemplateTable_ColumnMatcher.class,
			entityGenericType= A1TemplateColumn.class,
			dtoBeanKey="a1TemplateColumnDto",
			entityBeanKeys="a1TemplateColumn",
			readOnly=true
	)
	private List<A1TemplateColumnDto> a1TemplateColumnDtoList = new ArrayList<A1TemplateColumnDto>();


	private List btnIdList;

	public void setBtnMulti(String btnMulti) {
		this.btnMulti = btnMulti;

		List<Integer> idList = new ArrayList<>();
		if(StringUtils.isNull(this.btnMulti)) {
			this.btnIdList = idList;
			return;
		}
		String s1 = this.btnMulti.replaceAll(" ", "").replaceAll("\\[", "").replaceAll("\\]", "");
		if (StringUtils.isNull(s1)) {
			this.btnIdList = idList;
			return;
		}
		String[] split = s1.split(",");
		for(int i=0;i<split.length;i++){
			String s = split[i];
			int i1 = Integer.parseInt(s);
			idList.add(i1);
		}
		this.btnIdList = idList;
	}

	/*public List getBtnIdList() {
		List<Integer> idList = new ArrayList<>();
		if(StringUtils.isNull(this.btnMulti)) {
			return idList;
		}
		String s1 = this.btnMulti.replaceAll(" ", "").replaceAll("\\[", "").replaceAll("\\]", "");
		String[] split = s1.split(",");
		StringBuilder sb = new StringBuilder();
		for(int i=0;i<split.length;i++){
			String s = split[i];
			int i1 = Integer.parseInt(s);
			idList.add(i1);
		}
		return btnIdList;
	}*/

}
